<?php include("/includes/header.php") ?>
<?php include("/includes/sidebar.php") ?>
<?php $id = base64_decode($_GET[trim(base64_encode("idroom"), '=')]); ?>
<?php
	$gender = array('m' => 'Male', 'f' => 'Female');

	$paidStatus = array(0 => "Occupier", 1 => "Checkout");
	$sql = "SELECT * FROM front_office WHERE idroom = '".$id."' AND is_paid = '0'";
	$query = mysql_query($sql);
	$banyak_fo = mysql_num_rows($query);
	if ($banyak_fo > 0) {
		$query = mysql_query($sql);
		$data_fo = mysql_fetch_array($query);
		$data_fo = validateData($data_fo);
		$data_agent = getAgent($data_fo["idagent"]);
		# code...

		// CALCULATE THE DATE BETWEEN CHECKOUT AND CHECKIN
		// if (isset($checkout) && isset($checkin)) {
			# code...
			$diff = abs(strtotime($data_fo["checkout"]) - strtotime($data_fo["checkin"]));
			$days = floor($diff / (60*60*24));
		// }
	}

	// SELECTING TRAVEL AGEN
	// $sql_select_agent = "SELECT * FROM agent WHERE id = '".$idagent."'";
	// $query_select_agent = mysql_query($sql_select_agent);
	// $data_agent = mysql_fetch_array($query_select_agent);

	// SELECTING ROOM INFORMATION
	$data_room = getRoom($id);

	// $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
	// $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

	// printf("%d years, %d months, %d days\n", $years, $months, $days);
?>

<style type="text/css">
	tbody tr:not(:first-child) td {
		border-top: none !important;
		/*border-bottom: none !important;*/
	}
	tbody tr:not(:last-child) td {
		border-bottom: 1px dotted #ccc !important;
		/*border-bottom: none !important;*/
	}
</style>

<div class="header">
	<span class="active">
		<a href="fo-room-info.php?<?php echo $_SERVER["QUERY_STRING"]; ?>">
			<i class="fa fa-eye"></i> Room Info
		</a>
	</span>
	<span>
		<a href="fo-room-activity-table.php?<?php echo $_SERVER["QUERY_STRING"]; ?>">
			<i class="fa fa-table"></i> Table View
		</a>
	</span>
	<span>
		<a href="fo-room-activity-calendar.php?<?php echo $_SERVER["QUERY_STRING"]; ?>">
			<i class="fa fa-calendar"></i> Calendar View
		</a>
	</span>
	<span>
		<a href="fo-room-activity-graph.php?<?php echo $_SERVER["QUERY_STRING"]; ?>">
			<i class="fa fa-bar-chart-o"></i> Graph View
		</a>
	</span>
</div>

<div class="content row-fluid">
	<div class="span12 table-placer">
		<div class="alert alert-info"><h4>Room Info - <?php echo $data_room["nama"]; ?></h4></div>
		<div class="row-fluid index-pos-placer content">
			<div class="span6">
				<form class="form-horizontal">
					<fieldset>
						<legend>Room Info</legend>
						<dl>
							<dt>Name</dt>
							<dd><?php echo $data_room["nama"]; ?></dd>
							<dt>Price per night</dt>
							<dd><span class="label label-info">IDR</span> <?php echo number_format($data_room["harga"], 2, ',', '.'); ?></dd>
							<dt>Desciption</dt>
							<dd><?php echo $data_room["keterangan"]; ?></dd>
							<dt>Status</dt>
							<dd><span class="badge <?php echo ($banyak_fo > 0) ? "badge-important" : "badge-success" ; ?>"><?php echo ($banyak_fo > 0) ? "Occupied" : "Empty" ; ?></span></dd>
						</dl>
					</fieldset>
				</form>
			</div>
			<div class="span6">
				<form class="form-horizontal">
					<fieldset>
						<legend>Occupier Info</legend>
						<?php
							if ($banyak_fo > 0) {
						?>
						<dl>
							<dt>Name</dt>
							<dd><?php echo $data_fo["nama"]; ?></dd>
							<dt>Place / Date of Birth</dt>
							<dd><?php echo $data_fo["tempat_lahir"]; ?> / <?php echo date(  "F j, Y", strtotime( $data_fo["tanggal_lahir"] ) ); ?></dd>
							<dt>Gender</dt>
							<dd><?php echo $gender[$data_fo["jenis_kelamin"]]; ?></dd>
							<dt>Address</dt>
							<dd><?php echo $data_fo["alamat"]; ?></dd>
							<dt>Occupancy</dt>
							<dd><?php echo $data_fo["pekerjaan"]; ?></dd>
							<dt>Passport Number</dt>
							<dd><?php echo $data_fo["passport"]; ?></dd>
							<dt>Email / Phone Number</dt>
							<dd><?php echo $data_fo["email"]; ?> / <?php echo $data_fo["telepon"]; ?></dd>
							<dt>Coming From - Going To</dt>
							<dd><?php echo $data_fo["datang_dari"]; ?> - <?php echo $data_fo["pergi_ke"]; ?></dd>
							<dt>Arrival Date - Departure Date</dt>
							<dd><?php echo date(  "F j, Y", strtotime( $data_fo["tanggal_kedatangan"] ) ); ?> - <?php echo date(  "F j, Y", strtotime( $data_fo["tanggal_keberangkatan"] ) ); ?></dd>
							<dt>Checkin Date - Checkout Date</dt>
							<dd><?php echo date(  "F j, Y", strtotime( $data_fo["checkin"] ) ); ?> - <?php echo date(  "F j, Y", strtotime( $data_fo["checkout"] ) ); ?></dd>
							<dt>Agent</dt>
							<dd><?php echo (count($data_agent) > 1) ? "<a href='#' class='label label-info'>".$data_agent["nama"]."</a>" : "<span class='label'>Not Using Any Agent</span>" ; ?></dd>
						</dl>
						<?php
							} else {
						?>
						<div class="alert alert-info">
						  No one is currently staying in this room.
						</div>
						<?php
							}
						?>
					</fieldset>
				</form>
			</div>
		</div>
	</div>
</div>

<div class="footer">
</div>

<?php include("/includes/footer.php") ?>

<script type="text/javascript">
	$(document).ready(function() {
		var elPop;
		$('.index-pos').popover();
		$('.table-placer').on('click', '.index-pos', function(event) {
			event.preventDefault();
			/* Act on the event */
			// elPop = $(this);
			// $(".index-pos").popover("hide");
		});
		// $('.index-pos').on('hidden.bs.popover', function () {
		// 	elPop.popover("show");
		// })
	});
</script>